package com.mall.common.responses;

import java.io.Serializable;

public class ServerResponseEntity <T> implements Serializable {
    /**
     * 状态码
     */
    private String code;

    /**
     * 信息
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    /**
     * 版本
     */
    private String version;

    /**
     * 时间
     */
    private Long timestamp;

    private String sign;

    public ServerResponseEntity() {
        this.version="shop2024";
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    /**
     * 用户自定义成功的消息
    * */
    public static <T> ServerResponseEntity<T> success (String msg){
        ServerResponseEntity<T> response = new ServerResponseEntity<>();
        response.setMsg(msg);
        response.setCode(codeEnum.OK.value());
        return response;
    };

    /** NULL数据的成功的返回
     * */
    public static <T> ServerResponseEntity<T> success(){
        ServerResponseEntity<T> response = new ServerResponseEntity<>();
        response.setMsg(codeEnum.OK.getMsg());
        response.setCode(codeEnum.OK.value());
        return response;
    }

    public static <T> ServerResponseEntity<T> success(T data){
        ServerResponseEntity<T> response = new ServerResponseEntity<>();
        response.setMsg(codeEnum.OK.getMsg());
        response.setCode(codeEnum.OK.value());
        response.setData(data);
        return response;
    }

    /**
     * 错误的信息 自定义
     * */
    public static <T> ServerResponseEntity<T> fail(String msg){
        ServerResponseEntity<T> response = new ServerResponseEntity<>();
        response.setMsg(msg);
        response.setCode(codeEnum.SHOW_FAIL.value());
        return response;
    }

}
